package exception;

import javax.xml.bind.annotation.XmlAnyAttribute;

/**
 * 使用当前类测试异常抛出
 */
public class Person {

    public int getAge() {
        return age;
    }

    private int age;

    public Person(int age) {
        this.age = age;
    }

    public Person(){}

    public void setAge(int age) throws IllegalAgeException {
        if(age<0||age>200){
            //throw执行后,方法剩余代码就不会执行了

            //除了
//            throw new Exception("年龄不合法");
            throw new IllegalAgeException("年龄不合法");
        }
        this.age = age;
    }

}